package com.mlj.controller;

import com.mlj.pojo.Student;
import com.mlj.service.StudentService;
import com.mlj.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;

    /**
     * 学生列表页面
     */
    @RequestMapping("/studentlist_page")
    public String studentListPage(){
        return "studentlist";
    }
    /**
     * 学生信息添加页面
     */
    @RequestMapping("/addstudent_page")
    public String addStudentPage(){
        return "addstudent";
    }
    /**
     * 学生信息修改页面
     */
    @RequestMapping("/updatestudent_page")
    public String updateStudentPage(){
        return "updatestudent";
    }
    /**
     * 获取学生姓名
     */
    @RequestMapping("/studentName")
    @ResponseBody// json格式数据
    public List<Student> getStudentName(){
        return studentService.getStudentName();
    }
    /**
     * 分页查询视频列表
     */
    @RequestMapping("/studentlist")
    @ResponseBody// json格式数据
    public Result studentList(Integer page, Integer limit){
        return studentService.getStudentList(page,limit);
    }
    /**
     * 根据id删除
     */
    @RequestMapping("/delStudentById")
    @ResponseBody
    public Result delStudentById(Integer id){
        return studentService.delStudentById(id);
    }
    /**
     * 批量删除
     */
    @RequestMapping("/deleteBatch")
    @ResponseBody
    public Result deleteBatch(Integer [] ids){
        return studentService.deleteBatch(ids);
    }
    /**
     * 添加学生信息
     */
    @RequestMapping("/addstudent")
    @ResponseBody
    public Result addStudent(String studentName , String studentCode , String studentTelephone, Integer studentSex, String studentEnrolment , String studentClass , Integer studentStatus){
        return studentService.insertStudent(studentName ,studentCode ,studentTelephone,studentSex,studentEnrolment ,studentClass ,studentStatus);
    }

    @RequestMapping("/updateStudentById")
    @ResponseBody
    public Result updateStudentById(@RequestBody Student student){
        //System.out.println(student.getStudentId());
        return studentService.updateStudentById(student);
    }

    @RequestMapping("/search")
    @ResponseBody
    public Result search(String timerange,String keyword,Integer page,Integer limit){
        //System.out.println("时间--"+timerange+"--关键字"+keyword+"--"+page);
        return studentService.search(timerange,keyword,page,limit);
    }
}
